import 'package:aihu_getx_app/app/modules/chat/models/user_view_resp_vo.dart';
import 'package:aihu_getx_app/utils/constants.dart';
import 'package:aihu_getx_app/utils/init_system_data_util.dart';
import 'package:aihu_getx_app/widgets/common_image.dart';
import 'package:common_utils/common_utils.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:intl/intl.dart' as intl;

class ChatUserListItemWidget extends StatelessWidget {
  final UserViewRespVO data;

  const ChatUserListItemWidget(this.data, {super.key});

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.all(10),
      margin: const EdgeInsets.only(top: 1),
      decoration: const BoxDecoration(
        color: Colors.white,
      ),
      child: GestureDetector(
        onTap: () {
          // Get.toNamed(Routes.chatDetail, arguments: data);
        },
        child: MouseRegion(
          cursor: SystemMouseCursors.click,
          child: Row(
            children: [
              const SizedBox(width: 10),
              CommonImage(
                TextUtil.isEmpty(data.avatar) ? Constants.icon : data.avatar,
                fit: BoxFit.cover,
                width: 80,
                height: 80,
                isCircle: true,
              ),
              const SizedBox(width: 10),
              Expanded(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Row(
                      children: [
                        Chip(
                          padding: const EdgeInsets.all(0),
                          label: Text(
                              InitSystemDataUtil.getDictLabelByTypeAndValue(
                                      DictTypeEnum.chatUserOnlineStatus.type,
                                      data.onlineStatus) ??
                                  ''),
                          deleteIconColor: Colors.white,
                          labelStyle: Get.textTheme.bodySmall?.copyWith(
                            color: Colors.white,
                          ),
                          backgroundColor: data.onlineStatus == 2
                              ? Colors.grey
                              : data.onlineStatus == 3
                                  ? Colors.grey
                                  : data.onlineStatus == 1
                                      ? Colors.red
                                      : Colors.green,
                        ),
                        Chip(
                          padding: const EdgeInsets.all(0),
                          label: Text(
                              InitSystemDataUtil.getDictLabelByTypeAndValue(
                                      DictTypeEnum.userType.type,
                                      data.userType) ??
                                  ''),
                          deleteIconColor: Colors.white,
                          labelStyle: Get.textTheme.bodySmall?.copyWith(
                            color: Colors.white,
                          ),
                          backgroundColor: data.userType == 2
                              ? Get.theme.primaryColor
                              : Get.theme.secondaryHeaderColor,
                        ),
                        const Expanded(child: Text("")),
                        Text(
                          data.msgTime ??
                              intl.DateFormat('yyyy-MM-dd HH:mm:ss')
                                  .format(DateTime.now()),
                          style: Get.textTheme.bodySmall,
                        ),
                      ],
                    ),
                    Text(
                      "${data.nickname}[${data.mobile}]",
                      maxLines: 1,
                      overflow: TextOverflow.ellipsis,
                      style: Get.textTheme.titleSmall,
                    ),
                    Text(
                      data.msgContent ?? '没有消息',
                      style: Get.textTheme.bodySmall,
                      maxLines: 1,
                      overflow: TextOverflow.ellipsis,
                    ),
                  ],
                ),
              ),
              const SizedBox(width: 10),
            ],
          ),
        ),
      ),
    );
  }
}
